﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DX.CRC.Common.Entities;
using StuMngVan.Entities;

namespace StuMngVan.Dals
{
    class Dal4Course : DalBase
    {
        public static List<Course> SearchAllCourses(string name)
        {
            QueryObject qo = CreateQO();

            qo.CmdText = @"SELECT [ID]
	            ,[Name]
                ,[Remark]
            FROM [dbo].[TbCourse] WHERE IsActive=1 and Name like '%'+@Name+'%'";

            qo.AddParam("@Name", name);

            return qo.xExecuteList<Course>();
        }

        public static void InsertCourse(string name, string remark)
        {
            QueryObject qo = CreateQO();

            qo.CmdText = @"INSERT INTO [dbo].[TbCourse]
                   ([Name]
                   ,[IsActive]
                   ,[CreateTime]
                   ,[Remark])
             VALUES
                   (@Name
                   ,1
                   ,getutcdate()
                   ,@Remark)";

            qo.AddParam("@Name", name);
            qo.AddParam("@Remark", remark);

            qo.xExecuteNonQuery();
        }

        public static void DeleteCourse(Course course)
        {
            QueryObject qo = CreateQO();

            qo.CmdText = @"update TbCourse 
                  set IsActive = 0
                  WHERE ID=@ID";

            qo.AddParam("@ID", course.ID);

            qo.xExecuteNonQuery();
        }
    }
}
